<?php /** @noinspection ALL */

namespace app\admin\controller;

use think\response\Json;

class System extends Base
{
    public function initialize()
    {
        parent::initialize();
    }


    /**
     * 获取当前登录的用户信息
     */
    public function get_login_user(): Json
    {
        $userId = request()->user['id'];
        $admin = $this->getAdminService()->getAdminById($userId);
        $data = [
            'id' => $admin->getId(),
            'username' => $admin->getUsername(),
            'status' => $admin->getStatus(),
            'statusRemark' => $admin->getStatusRemark(),
            'isSuper' => $admin->getIsSuper(),
            'addTime' => $admin->getAddTime()
        ];
        return $this->requestSuccessReturn($data);
    }

    //获取当前登录的用户权限列表
    public function get_admin_menus()
    {
        $data = $this->getAdminMenusData();
        return $this->requestSuccessReturn($data);
    }

    private function getAdminMenusData(): array
    {
        return [
            [
                'name' => 'Dashboard',
                'path' => '/dashboard',
                'component' => '/index/index',
                'meta' => [
                    'title' => '工作台',
                    'icon' => '&#xe81a;'
                ],
                'children' => [
                    [
                        'path' => 'console',
                        'name' => 'Console',
                        'component' => '/dashboard/console',
                        'meta' => [
                            'title' => '工作台',
                            'keepAlive' => false,
                            'fixedTab' => true
                        ]
                    ]
                ]
            ],
            [
                'name' => 'Content',
                'path' => '/content',
                'component' => '/index/index',
                'meta' => [
                    'title' =>  '内容管理',
                    'icon' => '&#xe672;'
                ],
                'children' => [
                    [
                        'path' => 'subject',
                        'name' => 'Subject',
                        'component' => '/content/subject',
                        'meta' => [
                            'title' =>  '题目管理',
                            'keepAlive' => true,
                        ]
                    ],
                    [
                        'path' => 'subjectExt',
                        'name' => 'SubjectExt',
                        'component' => '/content/subjectExt',
                        'meta' => [
                            'title' =>  '题目扩展管理',
                            'keepAlive' => true,
                        ]
                    ]
                ]
            ],
            [
                'name' => 'System',
                'path' => '/system',
                'component' => '/index/index',
                'meta' => [
                    'title' =>  '系统管理',
                    'icon' => '&#xe7b9;'
                ],
                'children' => [
                    [
                        'path' => 'admim',
                        'name'  =>  'Admim',
                        'component' => '/system/admin',
                        'meta' => [
                            'title' =>  '管理员管理',
                            'keepAlive' => true,
                        ]
                    ],
                    [
                        'path' => 'user',
                        'name' => 'User',
                        'component' => '/system/user',
                        'meta' => [
                            'title' =>  '用户管理',
                            'keepAlive' => true,
                        ]
                    ]
                ]
            ]
        ];
    }
}